<template>
  <div class="app-container">
    <div style="overflow:hidden">
      <addDialog v-if="orderOrderdialogShow" @close="close" @update="getOrderPartnerAll" :id="id"></addDialog>
      <el-form style="float:left">
        <el-form-item label="手机号" label-width="60px" class="input">
          <el-input v-model="phoneNum" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item label="时间查询" :label-width="formLabelWidth" class="input">
            <el-date-picker
              v-model="dateArr"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
        </el-form-item>
      </el-form>
      <el-button type="primary" icon="el-icon-search" style="float:left;margin-left:10px" @click="getOrderPartnerAll">查询</el-button>
      <el-button type="primary" icon="el-icon-plus" style="float:left;margin-left:10px" @click="addOrder">新增</el-button>
    </div>
    <el-table :data="orderData" border style="width: 100%">
      <el-table-column prop="retailerName"     label="电商名称"         width="100"></el-table-column>
      <el-table-column prop="retailerNo"       label="电商代码"         width="100"></el-table-column>
      <el-table-column prop="createTime"      label="订单创建时间"       width="180"></el-table-column>
      <el-table-column prop="investmentTerm"  label="投资期限"       width="80"></el-table-column>
      <el-table-column prop="orderIdPartner"  label="p2p商家订单id"       width="120"></el-table-column>
      <el-table-column prop="projectType"     label="投资项目名称"       width="110"></el-table-column>
      <el-table-column prop="rebateAmonut"    label="返利总额"       width="80"></el-table-column>
      <el-table-column label="状态"      width="100">
        <template slot-scope="scope">
          <span>{{scope.row.status===0?'待处理':scope.row.status===1?'通过审核':'未通过审核'}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="userName"       label="用户名"       width="100"></el-table-column>
      <el-table-column prop="userPhoneNum"       label="用户手机号"       width="120"></el-table-column>
      <el-table-column label="操作"       min-width="250">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="audit(scope,'1')" :disabled="scope.row.status!==0">审核通过</el-button>
          <el-button type="danger" size="mini" @click="audit(scope,'2')" :disabled="scope.row.status!==0">审核不通过</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="curPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="size">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import moment from 'moment'
import { orderPartnerAll, orderPartnerCheck } from 'api/order'
import addDialog from './components/addDialog'
export default {
  components: {
    addDialog
  },
  data() {
    return {
      orderOrderdialogShow: false,
      orderData: [],
      pageSize: 10,
      curPage: 1,
      size: 0,
      phoneNum: '',
      formLabelWidth: '100px',
      dateArr: []
    }
  },
  created() {
    this.getOrderPartnerAll()
  },
  methods: {
    async getOrderPartnerAll() {
      const parm = {
        pageSize: this.pageSize,
        curPage: this.curPage - 1,
        phoneNum: this.phoneNum
      }
      if (this.dateArr == null || this.dateArr.length === 0) {
        parm.startTime = ''
        parm.endTime = ''
      } else {
        parm.startTime = moment(this.dateArr[0]).format('YYYY-MM-DD')
        parm.endTime = moment(this.dateArr[1]).format('YYYY-MM-DD')
      }
      try {
        let back = await orderPartnerAll(parm)
        back = back.data
        if (back.resultCode === '200') {
          this.orderData = back.result
          this.size = back.size
        }
      } catch (err) {
        this.$alert('请求出错', '提示')
      }
    },
    async audit(scope, status) {
      console.log(scope.row)
      const parm = {
        orderIdPartner: scope.row.orderIdPartner,
        companyNo: scope.row.companyNo,
        status: status
      }
      try {
        let back = await orderPartnerCheck(parm)
        back = back.data
        if (back.resultCode === '200') {
          this.getOrderPartnerAll()
        }
      } catch (err) {
        this.$alert('请求出错', '提示')
      }
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getOrderPartnerAll()
    },
    handleCurrentChange(val) {
      this.curPage = val
      this.getOrderPartnerAll()
    },
    addOrder() {
      this.id = ''
      this.orderOrderdialogShow = true
    },
    close() {
      this.orderOrderdialogShow = false
    }
  }
}
</script>
<style scoped>
  .block{
    float: right;
    margin-top:20px;
  }
  .input{
    float: left;
  }
</style>

